<?php

declare(ENCODING = 'UTF-8');

/*                                                                        *
 * This script is part of the TYPO3 project - inspiring people to share!  *
 *                                                                        *
 * TYPO3 is free software; you can redistribute it and/or modify it under *
 * the terms of the GNU General Public License version 2 as published by  *
 * the Free Software Foundation.                                          *
 *                                                                        *
 * This script is distributed in the hope that it will be useful, but     *
 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHAN-    *	
 * TABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General      *
 * Public License for more details.                                       *
 *                                                                        */	

/**
 * @package auxo
 * @subpackage tests
 * @version $Id$
 */

/**	
 * Testcases: Configuration
 *	
 * @package auxo
 * @subpackage core	
 * @version $Id$	
 * @copyright Copyright belongs to the respective authors
 * @author AHN
 * @license http://opensource.org/licenses/gpl-license.php GNU Public License, version 2
 */
class tx_auxo_Configuration_testcase extends PHPUnit_Framework_testcase  {
	private $configuration = array();
	/**
	 * Sets up a test enviroment of this testcase.
	 */
	public function setUp() {
		$fixture['configurations.'] = array('section1.' => 
												array('section11.' => 
													array('section111' => 'value111')),
											'section2.' =>
												array('section22.' =>
													array('section222' => 'value222')),
											'section3' => 'value3'
									  );
		$this->configuration = new tx_auxo_Configuration($fixture);
	}
	
	/**
	 * Testcase: Get a single value on deepest level
	 * 
	 * @return void
	 */
	public function testGetSingleValueOnDeepestLevel() {
		$this->AssertType('tx_auxo_Configuration', $this->configuration);
		$this->AssertEquals('value111', $this->configuration->get('section1.section11.section111'));
	}

	/**
	 * Testcase: Get a single value on highest level
	 * 
	 * @return void
	 */
	public function testGetSingleValueOnHighestLevel() {
		$this->AssertType('tx_auxo_Configuration', $this->configuration);
		$this->AssertEquals('value3', $this->configuration->get('section3'));
	}
	

	/**
	 * Testcase: Get values as array
	 * 
	 * @return void
	 */
	public function testGetValuesAsArray() {
		$this->AssertType('tx_auxo_Configuration', $this->configuration);
		$this->AssertType('array', $result = $this->configuration->get('section1.'));
		$this->AssertEquals(1, count($result));
		$this->AssertTrue(isset($result['section11.']));
		$this->assertTrue(isset($result['section11.']['section111']));
		$this->assertEquals('value111', $result['section11.']['section111']);		
	}
	
	/**
	 * Testcase: Set and overwrite and existing single value
	 *
	 * @return void
	 */
	public function testSetAndOverwriteSingleValue() {
		$this->AssertType('tx_auxo_Configuration', $this->configuration);
		$this->configuration->set('section1.section11.section111', 'foobar');
		$this->assertEquals('foobar', $this->configuration->get('section1.section11.section111'));
	}

	/**
	 * Testcase: Set a new parameter and with a single value
	 *
	 * @return void
	 */
	public function testSetNewParameterAndValue() {
		$this->AssertType('tx_auxo_Configuration', $this->configuration);
		$this->configuration->set('section1.section11.section112', 'Paris');
		$this->assertEquals('Paris', $this->configuration->get('section1.section11.section112'));
	}

	/**
	 * Testcase: Set a new parameter in a new section and with a single value
	 *
	 * @return void
	 */
	public function testSetNewSectionNewParameterAndValue() {
		$this->AssertType('tx_auxo_Configuration', $this->configuration);
		$this->configuration->set('section4.section44.section444', 'berlin');
		$this->assertEquals('berlin', $this->configuration->get('section4.section44.section444''));
	}
	
	/**
	 * Tears down a created test enviroment of this testcase.
	 */
	public function tearDown() {
		unset($this->configuration);
	}
}